<!-- 轮播图 -->
<template>
	<view class="banner">
		<swiper class="swiper" :autoplay="true" @change="swiper_change" :interval='2000' :style="{height: swiperHeight,background: '#fff'}">
			<swiper-item v-for="(item,index) in banners" :key="index">
				<view class="img_box" >
					<image :style="{height: swiperHeight}" :src="item.img" ></image>
					<!-- <image :src="" mode="heightFix"></image> -->
				</view>
			</swiper-item>
		</swiper>
		<view class="dots">
			<view :style="{background: background}" :class="{'dot_active' : bot_index === index}" class="dot" v-for="(item,index) in banners.length"
			 :key="index"></view>
		</view>
	</view>
</template>
<script>
    import mixins from '@/common/mixins.js';
	export default {
        mixins:[mixins],
		props: {
			banners: {
				type: Array,
				default: []
			},
			background: {
				type: String,
				default: '#FFFFFF'
			},
			swiperHeight: {
				type: String,
				default: '300rpx'
			},
			heightFix: {
				type: Boolean,
				default: false
			}
		},
		components: {},
		data() {
			return {
				bot_index: 0,
			};
		},
		computed: {},
		methods: {
			swiper_change(e) {
				this.bot_index = e.detail.current;
			},
		},
		beforeCreate() {},
		created() {},
		beforeMount() {},
		mounted() {
            // #ifdef MP-ALIPAY
            this.getDom('.banner').exec((res) => {
                uni.setStorage({
                    key:'bannerDom',
                    data:res
                })
            })
            // #endif
        },
		beforeUpdate() {},
		updated() {},
		beforeDestroy() {},
		destroyed() {},
	};
</script>
<style scoped lang='scss'>
	.banner {
		/* padding: 16rpx 0; */
		position: relative;
		border-radius: 16rpx;

		.swiper {
			overflow: hidden;
			border-radius: 16rpx;

			.img_box {
				border-radius: 16rpx;
				display: flex;
				justify-content: center;

				image {
					border-radius: 16rpx;
					width: 100%;
					height: 100%;
					object-position: center center;
				}
			}
		}

		.dots {
			position: absolute;
			left: 0;
			right: 0;
			bottom: 24rpx;
			display: flex;
			justify-content: center;
			flex-direction: row;

			.dot {
				width: 8rpx;
				height: 8rpx;
				background-color: #fff;
				margin-right: 10rpx;
				border-radius: 50%;

				&:last-child {
					margin-right: 0;
				}
			}

			.dot_active {
				width: 24rpx !important;
				height: 8rpx !important;
				border-radius: 999px !important;
			}
		}
	}
</style>
